package server;

/**
 * class to represent a transaction between two unique accounts.
 * @author Rasmus Stjerne, Joachim Lindholm, Daniel Gramstrup, Pamela Pedersen
 *
 */
public class Transaction {

	// Enum to identify the status of the transaction
	public enum Status {
		accept, decline, pending
	}

	//Private transaction fields
	private int id;
	private String sender;
	private String recipient;
	private double amount;

	// Enum status field
	private Status status;

	/**
	 * Transaction constructor. The status of the transaction is by default pending
	 * @param sender - Sender of the transaction
	 * @param recipient - Recipient of the transaction
	 * @param amount - Amount is limited by the the senders balance
	 * @param id - Defined by the system
	 */
	public Transaction(String sender, String recipient, double amount, int id ) {
		this.sender = sender;
		this.recipient = recipient;
		this.amount = amount;
		this.id = id;
		this.status = Status.pending;
	}

	/**
	 * Change the status of a transaction to accepted
	 */
	public void accept() {
		this.status = Status.accept;
	}
	

	/**
	 * Change the status of a transaction to declined
	 */
	public void decline() {
		this.status = Status.decline;
	}
	
	//Simple get methods
	public double getAmount() {
		return this.amount;
	}
	
	public String getSender() {
		return sender;
	}

	public String getRecipient() {
		return recipient;
	}

	public Status getStatus() {
		return this.status;
	}
	
	public int getID(){
		return this.id;
	}

	/**
	 * Override the toString method of the transaction object
	 */
	public String toString() {
		return "From: " + this.sender + "\tTo: " + this.recipient
				+ "\t\t Amount: " + this.amount + "\t [ID = "+this.id+ "]";
	}
}
